import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import NewPage from '@/components/NewPage'
// import NewPageSub from '@/components/NewPageSub'
import NewPageSub from '@/components/NewPageSub'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/newPage',
      name: 'NewPage',
      component: NewPage,
      meta: {
        title: "测试啦傻吊"
      },
      children: [{// 嵌套子集页面
        path: '/newPageSub', // 这里确认
        name: 'NewPageSub',
        component: NewPageSub,
        meta: {
          title: "new page sub "
        }
      }]
    }
  ]
});


//  路由测试

const isLogin  = true ;
//  路由拦截
router.beforeEach(function(to,from,next){
    console.log(to.name);
    console.log(from.name);
    // console.log(next.name);
    // 如果没登录就跳转到登录页面
    if(!isLogin && to.name !='HelloWorld' ){
      next({path:'/'}); 
    }else{
      next();
    }

});

export default router